import { message } from 'element-ui'
// vue/dist/vue.js
// 5589
var isHTMLTag = makeMap(
  'html,body,base,head,link,meta,style,title,' +
    'address,article,aside,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' +
    'div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,' +
    'a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,' +
    's,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,' +
    'embed,object,param,source,canvas,script,noscript,del,ins,' +
    'caption,col,colgroup,table,thead,tbody,td,th,tr,' +
    'button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,' +
    'output,progress,select,textarea,' +
    'details,dialog,menu,menuitem,summary,' +
    'content,element,shadow,template,blockquote,iframe,tfoot'
)
// 117
function makeMap(str, expectsLowerCase) {
  var map = Object.create(null)
  var list = str.split(',')
  for (var i = 0; i < list.length; i++) {
    map[list[i]] = true
  }
  return expectsLowerCase
    ? function(val) {
      return map[val.toLowerCase()]
    }
    : function(val) {
      return map[val]
    }
}
const map = new Map()
export const install = function(Vue, options) {
  const importAll = require.context('@/globalComponent', true, /\.vue$/)
  importAll.keys().map((path) => {
    const router = importAll(path).default || importAll(path)
    if (isHTMLTag(router.name)) {
      message.error(`${router.__file}组件名字与原生标签冲突`)
      return
    }
    if (map.get(router.name)) {
      message.error('组件名字不能与之前组件名字冲突')
      return
    } else {
      map.set(router.name, router.__file)
    }
    Vue.component(router.name, router)
  })
}
